﻿module Analyzer.Data

open Casanova
open Casanova.Core
open Casanova.Utilities
open Casanova.Coroutines
open Casanova.Game
open Casanova.Math
open Casanova.Drawing
open Casanova.StandardLibrary.Core
open Casanova.StandardLibrary.Physics
open VirtualCity.World
open VirtualCity.Main
open VirtualCity.CityDescription
open VirtualCity.City
open VirtualCity.PlanDescription
open VirtualCity.Plan
open VirtualCity.Scripts
open VirtualCity.Scripts.Planner


type Activity =
  | Home = 0
  | Work = 1
  | Leisure = 2
  | Travel  = 3
  | NumActivities = 4

and WorldAnalysisData = 
  {
    ActivitiesGrid : SpatialGrid<ResizeArray<Activity>>
    BuildingsGrid  : SpatialGrid<ResizeArray<Building>>
    Agents         : ResizeArray<AgentAnalysis>
  }

and SpatialGrid<'a> =
  {
    Cells     : 'a [][]
    CellSize  : Vector2<m>
  } with member this.Item (i,j) = this.Cells.[i].[j]
         member this.Item (v:Vector2<m>) = 
          let i = round(v.X / this.CellSize.X) |> int
          let j = round(v.Y / this.CellSize.Y) |> int
          this.Cells.[i].[j]

and AgentAnalysis =
  {
    Agent        : Agent
    mutable PositionAverage : Vector2<m>
    mutable PositionVariance : Vector2<m^2>
    Observations : ResizeArray<Observation>
    Clusters     : ResizeArray<Cluster>
  }

and Observation =
  {
    Location          : Vector2<m>
    Velocity          : Vector2<m/s>
    Time              : DateTime
    PossibleMatches   : PossibleMatch[]
  }

and PossibleMatch =
  {
    Activity    : Activity
    Confidence  : float32
  }

and Cluster =
  {
    Centroid      : Observation
    Variance      : Observation
  }
